package com.magic.gre.base.dialog;

import com.noname.lib_base_java.entity.NetFielBean;
import com.noname.lib_base_java.mvp.BaseContract;
import com.noname.lib_base_java.util.ToastUtil;

import java.util.List;

/**
 * Author: Lmoumou
 * Date: 2019-01-02 11:53
 * 文件名: BaseMVPDialog
 * 描述:
 */
public abstract class BaseMVPDialog <P extends BaseContract.BasePresenter> extends BaseBottomDialog
        implements BaseContract.BaseView{

    protected P mPresenter = creatPresenter();

    protected abstract P creatPresenter();
    private LoadingDialog loadingDialog;
    //是否有loading任务
    private boolean hasLoading = false;
    /**
     * 网络错误
     */
    @Override
    public void onNetError(String msg) {

        hideLoadDialog();

    }

    @Override
    public void showEmpty() {

    }

    @Override
    public void showContent() {

    }

    /**
     * 显示提示语句
     *
     * @param msg
     */
    @Override
    public void doPrompt(String msg) {
        synchronized (BaseMVPDialog.class) {
            ToastUtil.getInstance().showNormal(mContext, msg);
        }
    }

    /**
     * 显示加载提示弹窗
     */
    @Override
    public void showLoadDialog() {
        synchronized (BaseMVPDialog.class) {
            if (!hasLoading) {
                hasLoading = true;
                loadingDialog = new LoadingDialog();
                loadingDialog.showThis(getChildFragmentManager(), LoadingDialog.class.getSimpleName());
            }
        }
    }

    @Override
    public void onNoLogin() {

    }

    /**
     * 隐藏加载提示弹窗
     */
    @Override
    public void hideLoadDialog() {
        synchronized (BaseMVPDialog.class) {
            if (loadingDialog != null) {
                loadingDialog.dismissThis(loadingDialog.isResumed());
            }
        }
    }

    @Override
    public void upLoadFiels(List<NetFielBean> fielBeens) {
        ToastUtil.getInstance().showNormal(mContext, "文件上传成功");
        hideLoadDialog();
    }

    @Override
    public void upLoadFielsFail(String failMsg) {
        ToastUtil.getInstance().showNormal(mContext, "文件上传失败");
        hideLoadDialog();
    }



    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.detachView();
    }
}
